/**
 * Created by Administrator on 2016/8/1.
 */
var sceniclistService = require("../service/sceniclistService");
var uuid = require('node-uuid');

//获取景点列表
exports.sceniclist=function (req,res) {
    sceniclistService.sceniclist(function (err,datas) {
        if(err){
            res.send({success:false,msg:"查询失败"});
        }else{
            res.send( {success: 1,datas:datas});
        }
    })
}

//带条件商品列表
exports.shoplist=function (req,res) {
    var params = {
        sid:req.query.sid,
        standard:req.query.standard,
        timechoose:req.query.timechoose
    };
    sceniclistService.shoplist(params,function (err,datas) {
        if(err){
            res.send({success:false,msg:"查询失败"});
        }else{
            res.send( {success: 1,datas:datas});
        }
    })
}



exports.allshop=function (req,res) {
    var spotid=req.query.spotid;
    sceniclistService.allshop(spotid,function (err,datas) {
        if(err){
            res.send({success:false,msg:"查询失败"});
        }else{
            res.send( {success: 1,datas:datas});
        }
    })
}

//获取条件下商品
exports.findgoods=function (req,res) {

    var params = {
        timezone:req.query.timezone,
        type:req.query.type,
        timeone:req.query.timeone,
        startDate:req.query.startDate,
        endDate:req.query.endDate,
        spotid:req.query.spotid
    }
    sceniclistService.findgoods(params,function (err,datas) {
        if(err){
            res.send({success:false,msg:"查询失败"});
        }else{
            res.send( {success: 1,datas:datas});
        }
    })
}

//添加景点
exports.addsceniclist=function (req,res) {
    var userid = req.body.userid;
    var scenicname = req.body.scenicname;
    var scenicdes = req.body.scenicdes;
    sceniclistService.addsceniclist({scenicname:scenicname,scenicdes:scenicdes,userid:userid},function (err,rows) {
        if(err){
            res.send({success:false,msg:"查询失败"});
        }else{
            res.send( {success: 1,datas:rows});
        }
    })
}

//添加商品信息
exports.addticketlist=function (req,res) {
    var params = {
        userid:req.body.userid,
        tickername:req.body.tickername,
        ticketdes: req.body.ticketdes,
        ticketprice:req.body.ticketprice,
        tickettype:req.body.tickettype,
        specialtip:req.body.specialtip
    };
    sceniclistService.addticketlist(params,function (err,rows) {
        if(err){
            res.send({success:false,msg:"查询失败"});
        }else{
            res.send( {success: 1,datas:rows});
        }
    })
}

//获取票的详情信息
exports.ticketdetail=function (req,res) {
    var id = req.query.id;
    sceniclistService.ticketdetail(id,function (err,data) {
        if(err){
            res.send({success:false,msg:"查询失败"});
        }else{
            res.send( {success: 1,data:data});
        }
    })
}

//确认预定后保存预定商品信息
exports.reservemessage=function (req,res) {
    var obj = req.body.reserveobj;
    sceniclistService.reservemessage(obj,function (err,data) {
        if(err){
            res.send({success:false,msg:"插入失败"});
        }else{
            res.send( {success: 1,data:data});
        }
    })
}

//更新订单信息
exports.updatereservemes=function (req,res) {
    var payid = req.body.id;
    var payment = req.body.payment;
        payment =parseFloat(payment).toFixed(2)*100;
    sceniclistService.updatereservemes(payid,payment,function (err,data) {
        if(err){
            res.send({success:false,msg:"插入失败"});
        }else{
            res.send( {success: 1,data:data});
        }
    })
}

//确认预定后保存预定商品信息
exports.savetocart=function (req,res) {
    var obj = req.body.cartobj;
    sceniclistService.savetocart(obj,function (err,data) {
        console.log(err);
        if(err){
            res.send({success:false,msg:"插入失败"});
        }else{
            res.send( {success: 1,data:data});
        }
    })
}

exports.onlyreserve=function (req,res) {
        var userid=req.query.userid;
        var source=req.query.source;
        var deposit=req.query.deposit;
        var orderno=req.query.orderno;
       var params={
           id:uuid.unparse(uuid.v4(null, new Buffer(32), 0)),
           userid:userid,
           source:source,
           deposit:deposit,
           orderno:orderno,
           createAt:new Date(),
           isdeposit:1,
           status:1
       };
    sceniclistService.onlyreserve(params,function (err,data) {
        if(err){
            res.send({success:false,msg:"插入失败"});
        }else{
            res.send( {success: 1,data:data});
        }
    })
}